package kz.kstu.aecdemo.desktop.ui.frame;

import kz.kstu.aecdemo.desktop.ui.dialog.ChangePasswordDialog;
import kz.kstu.aecdemo.desktop.ui.page.MainPage;
import kz.kstu.aecdemo.desktop.util.GUIUtils;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author Filipp_Stankevich
 *         created: 25.07.11 20:40
 */
public class ApplicationFrame extends JFrame {

    private static final String SETTINGS_MENU = "Настройки";
    private static final String CHANGE_PASSWORD_MENU_ITEM = "Сменить пароль";
    private static final String TITLE = "AEC";

    private JMenuItem changePasswordMenuItem;

    private MainPage scanPage = new MainPage();

    public void initStaticComponents() {
        initMenuBar();
        initListeners();
        initWindow();
        setContentPane(scanPage.getRootPanel());
    }

    private void initMenuBar() {
        JMenuBar menuBar = new JMenuBar();

        JMenu settingsMenu = new JMenu(SETTINGS_MENU);
        changePasswordMenuItem = new JMenuItem(CHANGE_PASSWORD_MENU_ITEM);
        settingsMenu.add(changePasswordMenuItem);
        menuBar.add(settingsMenu);

        this.setJMenuBar(menuBar);
    }


    private void initWindow() {
        this.setTitle(TITLE);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setResizable(false);
        this.setSize(GUIUtils.preferredStartupScreenSize());
        this.setMinimumSize(GUIUtils.preferredStartupScreenSize());
    }

    private void initListeners() {

        changePasswordMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ChangePasswordDialog dialog = new ChangePasswordDialog();
                dialog.changePassword();
            }
        });
    }
}
